package com.sskj.givecoin.v.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.givecoin.MyAppLication;
import com.sskj.givecoin.common.Constants;
import com.sskj.givecoin.m.HttpConfig;
import com.sskj.givecoin.m.bean.AseetListBean;
import com.sskj.givecoin.m.bean.HttpData;
import com.sskj.givecoin.m.bean.UserInfo;
import com.sskj.givecoin.m.http.JsonCallBack;
import com.sskj.givecoin.p.base.BasePresenter;
import com.sskj.givecoin.utils.SPUtils;

/**
 * ProjectName：bfex
 * DESC: (类描述)
 * Created by 李岩 on 2018/6/29 0029
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
public class AssetManagePresenter extends BasePresenter<AssetManageActivity>{
    public void requestUserAssetList() {
        OkGo.<HttpData<AseetListBean>>post(HttpConfig.BASE_URL+HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<AseetListBean>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<AseetListBean>> response) {
                        HttpData<AseetListBean> httpListData = response.body();
                        if (httpListData.getStatus() == 200) {
                            mView.onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }

    public void upDateUserInfo(String mobile) {
        OkGo.<HttpData<UserInfo>>post(HttpConfig.BASE_URL + HttpConfig.GET_USER_INFO)
                .tag(mView)
                .params("mobile", mobile)
                .execute(new JsonCallBack<HttpData<UserInfo>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getStatus() == 200) {
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().is_shop);
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS, httpData.getData().getStatus());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS_HIGH, httpData.getData().getAuth_status());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_PAY_SIZE, httpData.getData().getPay_list());

                            if (httpData.getData().getRealname() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME, httpData.getData().getRealname());
                            }
                            if (httpData.getData().getIdcard() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_IDCORD, httpData.getData().getIdcard());
                            }
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_JGCODE, httpData.getData().getJigou_code());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_USDT, httpData.getData().getUsdt());

                            mView.updateUserInfo(httpData.getData());
                        }
                    }
                });
    }


}
